#include "widget.h"
#include "ui_widget.h"
#include <QPainter>
#include <QPen>
#include <QBrush>
Widget::Widget(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::Widget)
{
    ui->setupUi(this);
}

Widget::~Widget()
{
    delete ui;
}

void Widget::paintEvent(QPaintEvent *event)
{
    //在这里画画
    QPainter painter(this);

    //创建一支画笔
    QPen pen;
    pen.setColor(QColor(255,0,0));
    //设置画笔宽度
    pen.setWidth(3);
    //设置画笔风格
    pen.setStyle(Qt::DashLine);

    //创建画刷，给封闭图形填充颜色
    QBrush brush;
    brush.setColor(QColor(123,20,233));
    //默认情况下，画笔不填充，还得设置风格
    brush.setStyle(Qt::Dense3Pattern);

    //画家设置画刷
    painter.setBrush(brush);

    //画家设置画笔
    painter.setPen(pen);

    //画一条直线
    painter.drawLine(0,0,50,50);

    //画一个矩形
    painter.drawRect(50,50,40,40);

    //画一个圆形
    painter.drawEllipse(90,90,50,50);

    //画一段文字
    painter.drawText(200,200,"好好学习，天天向上");
}
